package com.rom.ratethehell.rate.custom_views;

import com.rom.ratethehell.R;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class SearchView extends RelativeLayout implements OnEditorActionListener {
	private OnEnterListener listener;
	public SearchView(Context context) {
		super(context);
		init(context);
	}
	public SearchView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	public SearchView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater inflater = (LayoutInflater)   getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
		inflater.inflate(R.layout.view_search, this);
		AutoCompleteTextView searchText = (AutoCompleteTextView) findViewById(R.id.search_text);
		//ImageView dataView = (ImageView) findViewById(R.id.search_icon);
		searchText.setOnEditorActionListener(this);
	}
	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		if (actionId == EditorInfo.IME_NULL) {
			listener.onEnter(v.getText().toString());
			return true;
		}
		return false;
	}
	public void setOnEnterListener(OnEnterListener l) {
		listener = l;
	}


}
